using System;

namespace Geekees.App.Cashbook.Lib.Helper
{
	/// <summary>
	/// Summary description for Session.
	/// </summary>
	public class SessionVar
	{
		public static int ERROR_INT_VAL = -1;

		#region Get

		/// <summary>
		/// Get Session Object
		/// </summary>
		public static object Get(string strKeyName)
		{
			return System.Web.HttpContext.Current.Session[strKeyName];
		}


		#endregion

		#region GetString

		/// <summary>
		/// Get Session String
		/// </summary>
		public static string GetString(string strKeyName)
		{
			object objSession=Get(strKeyName);
			if (objSession!=null)
			{
				return objSession.ToString();
			} else {
				return "";
			}
		}

		public static int GetInt(string strKeyName)
		{
			object objSession=Get(strKeyName);

			if (objSession!=null)
			{
				try
				{
					return int.Parse( objSession.ToString() );
				}
				catch{ return ERROR_INT_VAL;}
			} 
			else 
			{
				return ERROR_INT_VAL;
			}
		}


		#endregion

		#region GetBool

		/// <summary>
		/// Get Session Boolean
		/// </summary>
		public static bool GetBool(string strKeyName)
		{
			object objSession=Get(strKeyName);
			if (objSession!=null)
			{
				try
				{
					return bool.Parse(objSession.ToString());
				} catch {
					return false;
				}
			} else {
				return false;
			}
		}


		#endregion

		#region Set
        
		/// <summary>
		/// Set Session Value
		/// </summary>
		public static void Set(string strKeyName,object objValue)
		{
			System.Web.HttpContext.Current.Session[strKeyName]=objValue;
		}


		#endregion

	}
}
